using System;
using XTCast.Mp3;
using System.Threading;

namespace XTCast.Radio {
	
	/// <summary>An abstract base class that generates MP3-format Buffers to be streamed by Transmitters.
	/// A DJ subclass might get the data from local MP3 files (like FileDJ)
	/// or by relaying a stream from a remote MP3 server.
	/// </summary>
	
	public abstract class DJ {

		public DJ(Station station, BufferManager bm, StationConfig sc) {
			this.station = station;
			this.bm = bm;
			this.sc = sc;
		}

		public abstract void Skip(TimeSpan ts);

		public abstract TimeSpan Position
		{
			get;
			set;
		}

		SilenceDJ silDJ;
		virtual public SilenceDJ SilenceDJ {
			get {
				if (silDJ==null) silDJ=new SilenceDJ(station,bm,StationConfig);
				return silDJ;
			}
		}

		public virtual bool SkipTrack {
			get {
				if (skipTrack) {
					skipTrack=false;
					return true;
				} else return false;
			}
			set {
				if (value) bm.FlushBuffers();
				skipTrack = value;
			}
		}

		public abstract void Start();
		
		public virtual Station Station {
			get {
				return station;
			}
		}
				
		protected void LOG(int level, System.String msg) {
			switch (level) {
				case 1:
					Log.Error(this,msg);
					break;
				case 2:
					Log.Warn(this,msg);
					break;
				case 3:
					Log.Info(this,msg);
					break;
				case 4:
					Log.Verbose(this,msg);
					break;
				default:
					Log.WriteLine(this,msg);
					break;
			}
		}

		public override string ToString() {
			return String.Format("DJ{0,13:G}", Station.ID);
		}

		virtual public StationConfig StationConfig {
			get {
				return sc;
			}
		}

		private bool skipTrack=false;
		private StationConfig sc;
		protected internal BufferManager bm;
		protected internal Station station;		

	}
}